package com.google.jessewilson.codesearch.api;

/**
 * Controls the downloading of search results.
 *
 * @author jessewilson
 */
public interface ResultsPopulator {

  /**
   * The state of downloading results.
   */
  enum State {
    RESULTS_OUTSTANDING,
    ALL_RESULTS_DOWNLOADED,
    FETCHING;

    /**
     * Returns the most active of the two states.
     */
    public State union(State state) {
      if (this == FETCHING || state == FETCHING) {
        return FETCHING;
      }
      if (this == RESULTS_OUTSTANDING || state == RESULTS_OUTSTANDING) {
        return RESULTS_OUTSTANDING;
      }
      return ALL_RESULTS_DOWNLOADED;
    }
  }

  State getState();

  void fetchMoreResults();
}
